# SuperCV Backend API 测试脚本
# 测试用户信息：
# User ID: 2
# Token: test_token_12345678901234567890
# 手机号: 13800138000

$baseUrl = "http://localhost:8080"
$token = "test_token_12345678901234567890"
$headers = @{
    "Content-Type" = "application/json"
    "Authorization" = "Bearer $token"
    "token" = $token
}

Write-Host "=== SuperCV Backend API 测试 ===" -ForegroundColor Green
Write-Host "Base URL: $baseUrl" -ForegroundColor Yellow
Write-Host "Token: $token" -ForegroundColor Yellow
Write-Host ""

# 测试1: 获取用户信息
Write-Host "1. 测试获取用户信息 - GET /v1/user/info" -ForegroundColor Cyan
try {
    $response = Invoke-RestMethod -Uri "$baseUrl/v1/user/info" -Method GET -Headers $headers
    Write-Host "✓ 成功" -ForegroundColor Green
    Write-Host "响应: $($response | ConvertTo-Json -Depth 3)" -ForegroundColor White
} catch {
    Write-Host "✗ 失败: $($_.Exception.Message)" -ForegroundColor Red
}
Write-Host ""

# 测试2: 获取产品列表
Write-Host "2. 测试获取产品列表 - GET /v1/product/list" -ForegroundColor Cyan
try {
    $response = Invoke-RestMethod -Uri "$baseUrl/v1/product/list" -Method GET -Headers $headers
    Write-Host "✓ 成功" -ForegroundColor Green
    Write-Host "响应: $($response | ConvertTo-Json -Depth 3)" -ForegroundColor White
} catch {
    Write-Host "✗ 失败: $($_.Exception.Message)" -ForegroundColor Red
}
Write-Host ""

# 测试3: 获取简历模板列表
Write-Host "3. 测试获取简历模板列表 - GET /v1/resume/template/list" -ForegroundColor Cyan
try {
    $response = Invoke-RestMethod -Uri "$baseUrl/v1/resume/template/list" -Method GET -Headers $headers
    Write-Host "✓ 成功" -ForegroundColor Green
    Write-Host "响应: $($response | ConvertTo-Json -Depth 3)" -ForegroundColor White
} catch {
    Write-Host "✗ 失败: $($_.Exception.Message)" -ForegroundColor Red
}
Write-Host ""

# 测试4: 获取我的简历列表
Write-Host "4. 测试获取我的简历列表 - GET /v1/resume/list/mine" -ForegroundColor Cyan
try {
    $response = Invoke-RestMethod -Uri "$baseUrl/v1/resume/list/mine" -Method GET -Headers $headers
    Write-Host "✓ 成功" -ForegroundColor Green
    Write-Host "响应: $($response | ConvertTo-Json -Depth 3)" -ForegroundColor White
} catch {
    Write-Host "✗ 失败: $($_.Exception.Message)" -ForegroundColor Red
}
Write-Host ""

# 测试5: 获取VIP信息
Write-Host "5. 测试获取VIP信息 - GET /v1/vip/info" -ForegroundColor Cyan
try {
    $response = Invoke-RestMethod -Uri "$baseUrl/v1/vip/info" -Method GET -Headers $headers
    Write-Host "✓ 成功" -ForegroundColor Green
    Write-Host "响应: $($response | ConvertTo-Json -Depth 3)" -ForegroundColor White
} catch {
    Write-Host "✗ 失败: $($_.Exception.Message)" -ForegroundColor Red
}
Write-Host ""

# 测试6: 获取文章列表
Write-Host "6. 测试获取文章列表 - GET /v1/article/list" -ForegroundColor Cyan
try {
    $response = Invoke-RestMethod -Uri "$baseUrl/v1/article/list" -Method GET -Headers $headers
    Write-Host "✓ 成功" -ForegroundColor Green
    Write-Host "响应: $($response | ConvertTo-Json -Depth 3)" -ForegroundColor White
} catch {
    Write-Host "✗ 失败: $($_.Exception.Message)" -ForegroundColor Red
}
Write-Host ""

# 测试7: 获取订单列表
Write-Host "7. 测试获取订单列表 - GET /v1/order/list" -ForegroundColor Cyan
try {
    $response = Invoke-RestMethod -Uri "$baseUrl/v1/order/list" -Method GET -Headers $headers
    Write-Host "✓ 成功" -ForegroundColor Green
    Write-Host "响应: $($response | ConvertTo-Json -Depth 3)" -ForegroundColor White
} catch {
    Write-Host "✗ 失败: $($_.Exception.Message)" -ForegroundColor Red
}
Write-Host ""

# 测试8: 获取OSS STS凭证
Write-Host "8. 测试获取OSS STS凭证 - GET /v1/oss/sts" -ForegroundColor Cyan
try {
    $response = Invoke-RestMethod -Uri "$baseUrl/v1/oss/sts" -Method GET -Headers $headers
    Write-Host "✓ 成功" -ForegroundColor Green
    Write-Host "响应: $($response | ConvertTo-Json -Depth 3)" -ForegroundColor White
} catch {
    Write-Host "✗ 失败: $($_.Exception.Message)" -ForegroundColor Red
}
Write-Host ""

# 测试9: 检查Token过期时间
Write-Host "9. 测试检查Token过期时间 - GET /v1/auth/token/expire" -ForegroundColor Cyan
try {
    $response = Invoke-RestMethod -Uri "$baseUrl/v1/auth/token/expire" -Method GET -Headers $headers
    Write-Host "✓ 成功" -ForegroundColor Green
    Write-Host "响应: $($response | ConvertTo-Json -Depth 3)" -ForegroundColor White
} catch {
    Write-Host "✗ 失败: $($_.Exception.Message)" -ForegroundColor Red
}
Write-Host ""

Write-Host "=== API 测试完成 ===" -ForegroundColor Green
Write-Host "如果所有测试都成功，说明后端API功能正常!" -ForegroundColor Yellow